﻿// ZHGJDlg.cpp: 实现文件
//

#include "pch.h"
#include "3180101584SX1.h"
#include "ZHGJDlg.h"
#include "afxdialogex.h"

extern OpenImageClass OImageC;
// ZHGJDlg 对话框

IMPLEMENT_DYNAMIC(ZHGJDlg, CDialog)

ZHGJDlg::ZHGJDlg(CWnd* pParent /*=nullptr*/)
	: CDialog(IDD_DIALOG_ZHGJ, pParent)
{

}

ZHGJDlg::~ZHGJDlg()
{
}

void ZHGJDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(ZHGJDlg, CDialog)
	ON_BN_CLICKED(IDC_BUTTON_B_I, &ZHGJDlg::OnBnClickedButtonBI)
	ON_BN_CLICKED(IDC_BUTTON_I_B, &ZHGJDlg::OnBnClickedButtonIB)
	ON_BN_CLICKED(IDC_BUTTON_XCBM, &ZHGJDlg::OnBnClickedButtonXcbm)
	ON_BN_CLICKED(IDC_BUTTON_JOINT, &ZHGJDlg::OnBnClickedButtonJoint)
	ON_BN_CLICKED(IDC_BUTTON_SPLIT, &ZHGJDlg::OnBnClickedButtonSplit)
END_MESSAGE_MAP()


// ZHGJDlg 消息处理程序


void ZHGJDlg::OnBnClickedButtonBI()
{
	CString filename;

	LPCTSTR szFilter = _T("Bmp Files(*.bmp)|*.bmp|");		//提示保存文件的类型
	CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilter);		// CFileDialog的第一个参数标明是浏览(打开，TRUE)还是保存（FALSE）

	if (dlg.DoModal() == IDOK)		//返回值是OK，说明点击了“保存”/“确认”按钮，返回值是IDCANCEL，说明点击了取消
	{
		filename = dlg.GetPathName();		//保存文件的路径到filename变量中
		if (filename.Right(4) != _T(".bmp"))
			filename += _T(".bmp");
	}

	if (filename == "")
	{
		//AfxMessageBox("读取文件路径为空！");
		return;
	}

	OImageC.ReadBmpFileToImgDataFunction(filename);
	AfxMessageBox("Bmp->Img Done");
}


void ZHGJDlg::OnBnClickedButtonIB()
{
	CString filename;

	LPCTSTR szFilter = _T("000 Files(*.000)|*.000|");		//提示保存文件的类型
	CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilter);		// CFileDialog的第一个参数标明是浏览(打开，TRUE)还是保存（FALSE）

	if (dlg.DoModal() == IDOK)		//返回值是OK，说明点击了“保存”/“确认”按钮，返回值是IDCANCEL，说明点击了取消
	{
		filename = dlg.GetPathName();		//保存文件的路径到filename变量中
		if (filename.Right(4) != _T(".000"))
			filename += _T(".000");
	}

	if (filename == "")
	{
		//AfxMessageBox("读取文件路径为空！");
		return;
	}

	OImageC.ImgToBmpFileFunc(filename);
	AfxMessageBox("Img->Bmp Done");
	// TODO: 在此添加控件通知处理程序代码
}


void ZHGJDlg::OnBnClickedButtonXcbm()
{
	CString filename;

	LPCTSTR szFilter = _T("bmp Files(*.bmp)|*.bmp|");		//提示保存文件的类型
	CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilter);		// CFileDialog的第一个参数标明是浏览(打开，TRUE)还是保存（FALSE）

	if (dlg.DoModal() == IDOK)		//返回值是OK，说明点击了“保存”/“确认”按钮，返回值是IDCANCEL，说明点击了取消
	{
		filename = dlg.GetPathName();		//保存文件的路径到filename变量中
		if (filename.Right(4) != _T(".bmp"))
			filename += _T(".bmp");
	}

	if (filename == "")
	{
		//AfxMessageBox("读取文件路径为空！");
		return;
	}

	CString Fio;
	CString Fou = filename.Left(filename.GetLength() - 4) + "Out.bmp";
	CString Fcd = filename.Left(filename.GetLength() - 4) + "Out.txt";

	OImageC.RunLengthCode256BmpFunc(filename,Fou,Fcd);

	AfxMessageBox("Done");
}


void ZHGJDlg::OnBnClickedButtonJoint()
{
	CString sTifInPath1;
	CString sTifInPath2;
	CString sTifOutPath;

	GetDlgItemText(IDC_TIFIN1, sTifInPath1);
	if (sTifInPath1 == "")
	{
		AfxMessageBox("图像路径1为空");
		return;
	}
	GetDlgItemText(IDC_TIFIN2, sTifInPath2);
	if (sTifInPath2 == "")
	{
		AfxMessageBox("图像路径2为空");
		return;
	}
	GetDlgItemText(IDC_TIFOUT, sTifOutPath);
	if (sTifOutPath == "")
	{
		AfxMessageBox("保存路径为空");
		return;
	}

	sTifOutPath = sTifOutPath + "\\result.bmp";

	AfxMessageBox(sTifOutPath);

	OImageC.Image_Joint_Func(sTifInPath1, sTifInPath2, sTifOutPath);

	AfxMessageBox("Iamge Joint DONE");
}


void ZHGJDlg::OnBnClickedButtonSplit()
{
	CString sTifInPath;
	CString sTifOutPath1;
	CString sTifOutPath2;

	GetDlgItemText(IDC_TIFIN, sTifInPath);
	if (sTifInPath == "")
	{
		AfxMessageBox("图像路径为空");
		return;
	}
	GetDlgItemText(IDC_TIFOUT1, sTifOutPath1);
	if (sTifOutPath1 == "")
	{
		AfxMessageBox("保存路径1为空");
		return;
	}
	GetDlgItemText(IDC_TIFOUT2, sTifOutPath2);
	if (sTifOutPath2 == "")
	{
		AfxMessageBox("保存路径2为空");
		return;
	}

	sTifOutPath1 = sTifOutPath1 + "\\result1.bmp";
	sTifOutPath2 = sTifOutPath2 + "\\result2.bmp";

	OImageC.Image_Split_Func(sTifInPath, sTifOutPath1, sTifOutPath2);

	AfxMessageBox("Iamge Split DONE");
}
